<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>邀请加入大家庭</title>
    <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
    <meta name="format-detection" content="telephone=no"/>
    <link href="http://66xiaoqu.babytreeimg.com/css/group/invite.css" rel="stylesheet" type="text/css"/>
</head>
<body>

<div class="wrapper">
    <div class="content">
        <p><img class="laba" src="http://66xiaoqu.babytreeimg.com/images/group/laba.png"><span id="message"></span></p>

        <p>邀请你加入TA的大家庭，共享家人生活动态</p>

        <a id="bt" href="javascript:;" onclick="clickBt()"></a>
    </div>
    <img class="bg" src="http://66xiaoqu.babytreeimg.com/images/group/bg.jpg">
</div>

<div class="sale_pop" id="reged">
    <div class="loading-con">
        <p id="title" style="font-weight:bold;">确定加入TA的大家庭吗？</p>

        <p style="text-align: center" id="desc">确定后将自动退出现在的大家庭</p>

        <div class="only_btn" onclick="onlyClick()">
            <span id="only_bt">我知道了</span>
        </div>
        <ul class="btn">
            <li onclick="hidePop()" style="border-bottom-left-radius: 5px;" id="left">取消</li>
            <li onclick="confirm()" style="border-bottom-right-radius: 5px;color: #fb704c;" id="right">确认加入</li>
        </ul>

    </div>
</div>

</body>
</html>
<script type="text/javascript" src="http://66xiaoqu.babytreeimg.com/js/lib/zepto.js"></script>
<script>
    var params = {};
    var tempArray = window.location.search.split('?');
    if (tempArray.length == 2) {
        var parts = tempArray[1].split('&');
        for (var i = 0; i < parts.length; i++) {
            var nv = parts[i].split('=');
            if (!nv[0]) continue;
            params[nv[0]] = nv[1] || true;
        }
    }
  /*  var host = 'http://t.app.66xiaoqu.com';*/
    var host = 'http://app-66xiaoqu.babytree.com';
    var result;
    $.ajax({
        type: "get",
        url: host + '/rest/v1.0/group/inviteInfo/' + params.g + '/' + params.u + '/' + params.token + '/' + params.deviceId,
        success: function (data) {
            result = data.data;
            $('#groupName').text(data.data.groupName);
            $('#groupName_1').text(data.data.groupName);
            $('#message').text(data.data.message);

            if (data.data.status == 1) {
                $('#bt').text('已加入').addClass('btn-2')
            } else if (data.data.status == 0) {
                $('#bt').text('确定加入').addClass('btn-1')
            } else if (data.data.status == 2) {
                $('#bt').text('已退出').addClass('btn-2')
            }
        }
    });

    function clickBt() {
        if (result.status == 0) {
            if (result.isQuit == true) {
                $('.sale_pop').css('display', 'block');
            } else {
                post();
            }
        }
    }

    var flag = true;
    function hidePop() {
        $('.sale_pop').css('display', 'none');
    }

    function confirm() {
        $('.sale_pop').css('display', 'none');
        post();
    }

    function onlyClick() {
        hidePop();

        if (result.isSwitch == true) {
            if (params.type == 'android') {
                webviewhandle.goToHomePage(result.communityId, result.groupId);
            } else {
                document.location.href = "66xiaoqu:group:homepage##communityId=" + result.communityId + "&nbsp;groupId=" + result.groupId;
            }
        }
    }

    function post() {
        if (flag) {
            $.ajax({
                type: "post",
                dataType: "json",
                url: host + '/rest/v1.0/group/confirmToJoin/' + params.token + '/' + params.deviceId,
                data: {communityId: result.communityId, groupId: result.groupId, inviter: params.u},
                success: function (data) {
                    $('#bt').text('已加入').removeClass('btn-1').addClass('btn-2');
                    flag = false;
                    result.status = 1;
                    if (Number(params.vcode ? params.vcode : 0) < 301000) {

                        $('#title').text('加入成功');
                        $('#desc').text('您需要升级到最新版本才能使用家庭群组功能');
                        $('.only_btn').css('display', 'block');
                        $('.btn').css('display', 'none');
                        $('.sale_pop').css('display', 'block');

                    } else {
                        if (result.isSwitch == true) {
                            $('#title').text('加入成功');
                            $('#desc').text('您已成功加入到' + result.communityName + '的家');
                            $('#only_bt').text('我知道了');
                            $('.only_btn').css('display', 'block');
                            $('.btn').css('display', 'none');
                            $('.sale_pop').css('display', 'block');
                        } else {
                            if (params.type == 'android') {
                                webviewhandle.goToGroupInfo(result.groupId);
                            } else {
                                document.location.href = "66xiaoqu:group:info##groupId=" + result.groupId;
                            }
                        }
                    }
                }
            })
        }
    }

</script>
